var currentAnswerPtr = 1;
var showAns = false;
var stepBeforeAnswer = 0;

function showAnswer(stepNum)
{
    var indexvalue = 0;
    var ptr = null;
    var prompt = "";
    var ctr = 0;

    if (showAns == true)
    {

        answerInitialize(true);

        goToNextStep(stepNum, stepNum);

/*
        for (i=0;i<AnswerArray.length;i++)
        {
            if (AnswerArray[i].stepnum == stepNum)
            {
                indexvalue = i;
                break;
            }
        }
*/
        indexvalue = stepnum;

        /* We don't have sub command anymores
        //check to see if it has subcommands
        if (AnswerArray[indexvalue].substep == true)
        {
            var ctr = indexvalue;
            while ((AnswerArray[ctr].stepnum == stepNum) && (AnswerArray[ctr].substep == true) )
            {
                expandCommand(stepNum,ctr);
                ctr = ctr + 1;
            }
        }
        else
        {
            expandCommand(stepNum,indexvalue);
        }
        */
        expandCommand(stepNum,indexvalue);
    }
}

function expandCommand(stepNum,index)
{
    prompt = getPrompt(StepModeArray[stepNum]);
    writeToRouter(prompt);
    writeToRouter(AnswerArray[index][0].commandName);
    for (i=1; i < 16; i++)
	{
	    ptr = AnswerArray[index][0];
		if ( eval("ptr.param" + i).length > 0)
		   writeToRouter(" " + eval("ptr.param" + i));
	}
    writeToRouter("\n");

    if(AnswerArray[index+1][0].stepnum == AnswerArray[index][0].stepnum
    && AnswerArray[index+1][0].matrixCheck == True
    && AnswerArray[index][0].matrixCheck == True)
    {
		expandCommand(stepNum, index + 1); //recursion to show all answers (it works :P)
										   //Tony's answer to solve missing show answer steps 2/07/03
	}
}

function writeToRouter(Str)
{
    _root.HyperTerminal.sRouterB.output += Str;
}

function answerInitialize(flag)
{
    if (flag)
    {
        _root.HyperTerminal.sRouterB.output = "";
        _root.HyperTerminal.sRouterB._visible = true;
        _root.HyperTerminal.sRouterA._visible = false;
        _root.HyperTerminal.cursor._visible = false;
    }
    else
    {
        _root.HyperTerminal.sRouterB.output = "";
        _root.HyperTerminal.sRouterB._visible = false;
        _root.HyperTerminal.sRouterA._visible = true;
        _root.HyperTerminal.cursor._visible = true;
    }
}

function getPrompt(arg1)
{
var stepDevice = _root.routerInfoArray[_root.routerUsedForThisStep[_root.stepnum]].deviceType;
    //holds the string that is the new prompt
    var p = "";
    if (arg1 == "user") {

        if (stepDevice != "Switch 4006 Sup 2")
            p = ">";
        else
            p = "> ";

    } else if (arg1 == "enable") {

        if (stepDevice != "Switch 4006 Sup 2")
            p = "#";
        else
            p = "> (enable) ";

    } else if (arg1 == "global") {

        p = "(config)#";

    }

    else if (arg1.substr(0, 3) == "int") {
        p = "(config-if)#";
    }

    else if (arg1.substr(0, 3) == "sub") {
        p = "(config-subif)#";
    }

    else if (arg1.substr(0, 4) == "line") {
        p = "(config-line)#";
    }

    else if (arg1.substr(0, 6) == "router") {
        p = "(config-router)#";
    }

    else if (arg1.indexOf("controller") == 0) {
        p = "(config-controller)#";
    }

    else if (arg1.indexOf("extNacl") == 0) {
        p = "(config-ext-nacl)#";
    }

    else if (arg1.indexOf("mapClass") == 0) {
        p = "(config-map-class)#";
    }

    else if (arg1.indexOf("timeRange") == 0) {
        p = "(config-time-range)#";
    }

    else if (arg1.indexOf("dhcp") == 0) {
        p = "(dhcp-config)#";
    }

    else if (arg1.indexOf("routeMap") == 0) {
        p = "(config-route-map)#";
    }

    else if (arg1.indexOf("classMap") == 0) {
        p = "(config-cmap)#";
    }

    else if (arg1.indexOf("policyMap") == 0) {
        p = "(config-pmap)#";
    }

    else if (arg1.indexOf("policyMapClass") == 0) {
        p = "(config-pmap-c)#";
    }

    else if (arg1 == "vlanDB") {
        p = "(vlan)#";
    }
    else if (arg1 == "ATMPVC") {
    p = "(config-if-atm-vc)#";
    }
    else if (arg1 == "DOS")
    {
        p = " C:\\>";
    }
    else if (arg1 == "NameOnly")
    {
            p = "";
    }
trace("p = " + p);
    //set the new prompt and mode on the router in question
    return _root.rRouterA.run.hostname + p;
}
